package com.bigflexlib.ds.op
{


	import com.bigflexlib.ds.container.zet.IOWSet;
	import com.bigflexlib.ds.container.zet.IRSet;
	import com.bigflexlib.ds.container.zet.IRWSet;
	import com.bigflexlib.ds.container.zet.impl.RWDictionarySet;
	import com.bigflexlib.ds.container.zet.impl.owSet;
	import com.bigflexlib.utils.IOperator;
	import com.bigflexlib.utils.BasicTestBase;


	public class SetMappingOpTest extends BasicTestBase
	{



		// the original set... we will modify it
		private var ABCDE:IOWSet = owSet( [ "A","B","C","D","E" ] );
		
		// lower case
		private var abcde:IRSet = new RWDictionarySet( [ "a","b","c","d","e" ] );
		
		// lower case without letter e
		private var abcd:IRSet = new RWDictionarySet( [ "a","b","c","d" ] );

		// lower case without letter e
		private var abcdf:IRSet = new RWDictionarySet( [ "a","b","c","d", "f" ] );




		public function testSimpleChars( ):void
		{

			var result:IRWSet = new RWDictionarySet( );
			
			
			var op:IOperator = new SetMappingOp( ABCDE, result, toLowerCase );
			
			// result should now be lower case
			assertTrue( result.compare( abcde ).isEqual );

			// we remove letter e from the original set
			ABCDE.remove( "E" );
			
			
			// result should remain in sync
			assertTrue( result.compare( abcd ).isEqual );


			// we add letter f to the original set
			ABCDE.add( "F" );
			
			
			// result should remain in sync
			assertTrue( result.compare( abcdf ).isEqual );
			
			
			// disconnect
			op.dispose( );
			// do something while disconnected
			ABCDE.add( "Z" );
			
			
			// result should remain the same... it is disconnected
			assertTrue( result.compare( abcdf ).isEqual );

		}
		
		
		
		
		
		
		/**
		 * 
		 * Usecase: keep two sets in sync
		 * 
		 */		
		public function testSyncTwoSets( ):void
		{
		
			
			var set1:IOWSet = owSet( ["a"] );
			var set2:IOWSet = owSet( );
				
			var op:IOperator = new SetMappingOp( set1, set2 );	
				
				assertContainersEqual( set1, set2 );

			set1.add( "a" );
				assertContainersEqual( set1, set2 );
		
			set1.add( "b" );
				assertContainersEqual( set1, set2 );
		
			set1.remove( "a" );
				assertContainersEqual( set1, set2 );
		
			set1.add( 88 );
				assertContainersEqual( set1, set2 );
			
			set1.clear( );
				assertContainersEqual( set1, set2 );

		
		}
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		private function toLowerCase( e:* ):*
		{
			return String( e ).toLowerCase( );		
		}
		
		
		
		
	}

}